package giftmail.mq;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.springframework.jms.listener.SessionAwareMessageListener;

/**
 * SessionAwareMessageListener是为了方便我们在接收到消息后,
 * 并使用session的方式给对方发送一个回复的消息
 * @author Demo
 *
 */
public class ConsumerSessionAwareMessageListener implements SessionAwareMessageListener<TextMessage> {

	private Destination destination;  
	
	@Override
	public void onMessage(TextMessage message, Session session) throws JMSException {
		System.out.println("收到一条消息");  
        System.out.println("消息内容是：" + message.getText());
        //用Session创建destination的生产者
        MessageProducer producer = session.createProducer(destination);
        //用Session创建了对应的消息
        Message textMessage = session.createTextMessage("ConsumerSessionAwareMessageListener。。。");  
        //用创建好的生产者发送消息
        producer.send(textMessage);  
		
	}

	public Destination getDestination() {  
        return destination;  
    }  
   
    public void setDestination(Destination destination) {  
        this.destination = destination;  
    }
	
}
